{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "78c98603",
   "metadata": {},
   "source": [
    "# Numpy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbd99a38",
   "metadata": {},
   "source": [
    "## 创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a158dc9",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[80, 89, 86, 67, 79],\n",
       "       [78, 97, 89, 67, 81],\n",
       "       [90, 94, 78, 67, 74],\n",
       "       [91, 91, 90, 67, 69],\n",
       "       [76, 87, 75, 67, 86],\n",
       "       [70, 79, 84, 67, 84],\n",
       "       [94, 92, 93, 67, 64],\n",
       "       [86, 85, 83, 67, 80]])"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 创建ndarray\n",
    "score = np.array(\n",
    "[[80, 89, 86, 67, 79],\n",
    "[78, 97, 89, 67, 81],\n",
    "[90, 94, 78, 67, 74],\n",
    "[91, 91, 90, 67, 69],\n",
    "[76, 87, 75, 67, 86],\n",
    "[70, 79, 84, 67, 84],\n",
    "[94, 92, 93, 67, 64],\n",
    "[86, 85, 83, 67, 80]])\n",
    "\n",
    "score"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62631eec",
   "metadata": {},
   "source": [
    "## 效率对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5ccf9f74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 469 ms\n",
      "Wall time: 616 ms\n",
      "CPU times: total: 78.1 ms\n",
      "Wall time: 158 ms\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "import time\n",
    "import numpy as np\n",
    "a = []\n",
    "for i in range(100000000):\n",
    "    a.append(random.random())\n",
    "\n",
    "# 通过%time魔法方法, 查看当前行的代码运行一次所花费的时间\n",
    "%time sum1=sum(a)\n",
    "\n",
    "b=np.array(a)\n",
    "\n",
    "%time sum2=np.sum(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "67fc3064",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "999b9baf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., 1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1., 1., 1., 1.]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成0和1数组\n",
    "\n",
    "ones = np.ones([4, 8])\n",
    "ones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "632da0a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0.]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros_like(ones)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e21fc3c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5aea6c26",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe16aa3a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58e369b7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81bb72b7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18290ee2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad7d41cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "580565af",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a93dd03",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
